<!DOCTYPE html>












  


<html class="theme-next pisces use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
























<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2">

<link rel="stylesheet" href="/css/main.css?v=7.1.2">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.1.2">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.1.2">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.1.2">


  <link rel="mask-icon" href="/images/logo.svg?v=7.1.2" color="#222">







<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '7.1.2',
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false,"dimmer":false},
    back2top: true,
    back2top_sidebar: false,
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="图像识别技术是人工智能的一个重要领域。它是指对图像进行对象识别，以识别各种不同模式的目标和对像的技术。">
<meta name="keywords" content="AI进阶,机器学习,图像识别">
<meta property="og:type" content="article">
<meta property="og:title" content="机器学习-图像识别">
<meta property="og:url" content="https://rencheng.cc/2019/05/01/ml/图像识别/index.html">
<meta property="og:site_name" content="PHOENIX&#39;s Blog">
<meta property="og:description" content="图像识别技术是人工智能的一个重要领域。它是指对图像进行对象识别，以识别各种不同模式的目标和对像的技术。">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2019-05-01T08:35:28.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="机器学习-图像识别">
<meta name="twitter:description" content="图像识别技术是人工智能的一个重要领域。它是指对图像进行对象识别，以识别各种不同模式的目标和对像的技术。">



  <link rel="alternate" href="/atom.xml" title="PHOENIX's Blog" type="application/atom+xml">



  
  
  <link rel="canonical" href="https://rencheng.cc/2019/05/01/ml/图像识别/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>机器学习-图像识别 | PHOENIX's Blog</title>
  












  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">PHOENIX's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <h1 class="site-subtitle" itemprop="description">Enjoy the journey of life</h1>
      
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
    
      
    

    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">

    
    
    
      
    

    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
    
      
    

    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
    
      
    

    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-about">

    
    
    
      
    

    

    <a href="/about/" rel="section"><i class="menu-item-icon fa fa-fw fa-user"></i> <br>关于</a>

  </li>

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
        </li>
      
    </ul>
  

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://rencheng.cc/2019/05/01/ml/图像识别/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="任成">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.JPG">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="PHOENIX's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">机器学习-图像识别

              
            
          </h2>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-05-01 16:35:28" itemprop="dateCreated datePublished" datetime="2019-05-01T16:35:28+08:00">2019-05-01</time>
            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/教程/" itemprop="url" rel="index"><span itemprop="name">教程</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          

          
            <div class="post-symbolscount">
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                <span title="本文字数">6.1k</span>
              

              

              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>图像识别技术是人工智能的一个重要领域。它是指对图像进行对象识别，以识别各种不同模式的目标和对像的技术。<br><a id="more"></a></p>
<h1 id="图像识别"><a href="#图像识别" class="headerlink" title="图像识别"></a>图像识别</h1><figure class="highlight asciidoc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">业务数据---------&gt;特征数据-&gt;学习模型</span><br><span class="line">|    特征工程               ^</span><br><span class="line">|   TFIDF、MFCC、SIFT      |</span><br><span class="line"><span class="code">+--------------------------+</span></span><br></pre></td></tr></table></figure>
<h2 id="OpenCV基础"><a href="#OpenCV基础" class="headerlink" title="OpenCV基础"></a>OpenCV基础</h2><p>开源计算机视觉库<br>图像处理<br>提取图像特征<br>针对的图像的机器学习<br><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> cv2 <span class="keyword">as</span> cv</span><br><span class="line">original = cv.imread(<span class="string">'../data/forest.jpg'</span>)</span><br><span class="line">cv.imshow(<span class="string">'Original'</span>, original)</span><br><span class="line">blue = np.zeros_like(original)</span><br><span class="line">blue[..., <span class="number">0</span>] = original[..., <span class="number">0</span>]</span><br><span class="line">cv.imshow(<span class="string">'Blue'</span>, blue)</span><br><span class="line">green = np.zeros_like(original)</span><br><span class="line">green[..., <span class="number">1</span>] = original[..., <span class="number">1</span>]</span><br><span class="line">cv.imshow(<span class="string">'Green'</span>, green)</span><br><span class="line">red = np.zeros_like(original)</span><br><span class="line">red[..., <span class="number">2</span>] = original[..., <span class="number">2</span>]</span><br><span class="line">cv.imshow(<span class="string">'Red'</span>, red)</span><br><span class="line">h, w = original.shape[:<span class="number">2</span>]</span><br><span class="line">l, t = int(w / <span class="number">4</span>), int(h / <span class="number">4</span>)</span><br><span class="line">r, b = int(w * <span class="number">3</span> / <span class="number">4</span>), int(h * <span class="number">3</span> / <span class="number">4</span>)</span><br><span class="line">cropped = original[t:b, l:r]</span><br><span class="line">cv.imshow(<span class="string">'Cropped'</span>, cropped)</span><br><span class="line"><span class="comment">#scaled = cv.resize(original,</span></span><br><span class="line"><span class="comment">#	(int(w / 2), int(h / 2)),</span></span><br><span class="line"><span class="comment">#	interpolation=cv.INTER_LINEAR)</span></span><br><span class="line">scaled = cv.resize(original, <span class="literal">None</span>,</span><br><span class="line">	fx=<span class="number">2</span>, fy=<span class="number">2</span>,</span><br><span class="line">	interpolation=cv.INTER_LINEAR)</span><br><span class="line">cv.imshow(<span class="string">'Scaled'</span>, scaled)</span><br><span class="line">cv.waitKey();</span><br><span class="line">cv.imwrite(<span class="string">'./cropped.bmp'</span>, cropped)</span><br><span class="line">cv.imwrite(<span class="string">'./cropped.png'</span>, cropped)</span><br><span class="line">cv.imwrite(<span class="string">'./cropped.jpg'</span>, cropped)</span><br></pre></td></tr></table></figure></p>
<h2 id="边缘检测"><a href="#边缘检测" class="headerlink" title="边缘检测"></a>边缘检测</h2><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> cv2 <span class="keyword">as</span> cv</span><br><span class="line">original = cv.imread(<span class="string">'../data/chair.jpg'</span>,</span><br><span class="line">	cv.IMREAD_GRAYSCALE)</span><br><span class="line">cv.imshow(<span class="string">'Original'</span>, original)</span><br><span class="line">canny = cv.Canny(original, <span class="number">50</span>, <span class="number">240</span>)</span><br><span class="line">cv.imshow(<span class="string">'Canny'</span>, canny)</span><br><span class="line">cv.waitKey()</span><br></pre></td></tr></table></figure>
<h2 id="亮度提升"><a href="#亮度提升" class="headerlink" title="亮度提升"></a>亮度提升</h2><p>直方图均衡化<br><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> cv2 <span class="keyword">as</span> cv</span><br><span class="line">original = cv.imread(<span class="string">'../data/sunrise.jpg'</span>)</span><br><span class="line">cv.imshow(<span class="string">'Original'</span>, original)</span><br><span class="line">gray = cv.cvtColor(original, cv.COLOR_BGR2GRAY)</span><br><span class="line">cv.imshow(<span class="string">'Gray'</span>, gray)</span><br><span class="line">eq_gray = cv.equalizeHist(gray)</span><br><span class="line">cv.imshow(<span class="string">'EQ-Gray'</span>, eq_gray)</span><br><span class="line">yuv = cv.cvtColor(original, cv.COLOR_BGR2YUV)</span><br><span class="line">yuv[..., <span class="number">0</span>] = cv.equalizeHist(yuv[..., <span class="number">0</span>])</span><br><span class="line">eq_color = cv.cvtColor(yuv, cv.COLOR_YUV2BGR)</span><br><span class="line">cv.imshow(<span class="string">'EQ-Color'</span>, eq_color)</span><br><span class="line">cv.waitKey()</span><br></pre></td></tr></table></figure></p>
<h2 id="角点检测"><a href="#角点检测" class="headerlink" title="角点检测"></a>角点检测</h2><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> cv2 <span class="keyword">as</span> cv</span><br><span class="line">original = cv.imread(<span class="string">'../data/box.png'</span>,</span><br><span class="line">	cv.IMREAD_GRAYSCALE)</span><br><span class="line">cv.imshow(<span class="string">'Original'</span>, original)</span><br><span class="line">corners = cv.cornerHarris(original, <span class="number">7</span>, <span class="number">5</span>, <span class="number">0.04</span>)</span><br><span class="line">corners = cv.dilate(corners, <span class="literal">None</span>)</span><br><span class="line">mixture = original.copy()</span><br><span class="line">mixture[corners &gt; corners.max() * <span class="number">0.01</span>] = <span class="number">255</span></span><br><span class="line">cv.imshow(<span class="string">'Mixture'</span>, mixture)</span><br><span class="line">cv.waitKey()</span><br></pre></td></tr></table></figure>
<h2 id="STAR特征检测"><a href="#STAR特征检测" class="headerlink" title="STAR特征检测"></a>STAR特征检测</h2><p>几何结构<br><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> cv2 <span class="keyword">as</span> cv</span><br><span class="line">original = cv.imread(<span class="string">'../data/table.jpg'</span>)</span><br><span class="line">cv.imshow(<span class="string">'Original'</span>, original)</span><br><span class="line">gray = cv.cvtColor(original, cv.COLOR_BGR2GRAY)</span><br><span class="line">cv.imshow(<span class="string">'Gray'</span>, gray)</span><br><span class="line">star = cv.xfeatures2d.StarDetector_create()</span><br><span class="line">keypoints = star.detect(gray)</span><br><span class="line">mixture = original.copy()</span><br><span class="line">cv.drawKeypoints(original, keypoints, mixture,</span><br><span class="line">	flags=cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)</span><br><span class="line">cv.imshow(<span class="string">'Mixture'</span>, mixture)</span><br><span class="line">cv.waitKey()</span><br></pre></td></tr></table></figure></p>
<h2 id="SIFT特征检测"><a href="#SIFT特征检测" class="headerlink" title="SIFT特征检测"></a>SIFT特征检测</h2><p>突出亮度变化的方向<br><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> cv2 <span class="keyword">as</span> cv</span><br><span class="line">original = cv.imread(<span class="string">'../data/table.jpg'</span>)</span><br><span class="line">cv.imshow(<span class="string">'Original'</span>, original)</span><br><span class="line">gray = cv.cvtColor(original, cv.COLOR_BGR2GRAY)</span><br><span class="line">cv.imshow(<span class="string">'Gray'</span>, gray)</span><br><span class="line">sift = cv.xfeatures2d.SIFT_create()</span><br><span class="line">keypoints = sift.detect(gray)</span><br><span class="line">mixture = original.copy()</span><br><span class="line">cv.drawKeypoints(original, keypoints, mixture,</span><br><span class="line">	flags=cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)</span><br><span class="line">cv.imshow(<span class="string">'Mixture'</span>, mixture)</span><br><span class="line">cv.waitKey()</span><br></pre></td></tr></table></figure></p>
<h2 id="STAR-SIFT特征描述矩阵"><a href="#STAR-SIFT特征描述矩阵" class="headerlink" title="STAR-SIFT特征描述矩阵"></a>STAR-SIFT特征描述矩阵</h2><p>通过对STAR特征点做进一步基于SIFT算法的筛选，以样本矩阵的形式表现的图像特征信息。<br><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> cv2 <span class="keyword">as</span> cv</span><br><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> mp</span><br><span class="line">original = cv.imread(<span class="string">'../data/table.jpg'</span>)</span><br><span class="line">cv.imshow(<span class="string">'Original'</span>, original)</span><br><span class="line">gray = cv.cvtColor(original, cv.COLOR_BGR2GRAY)</span><br><span class="line">cv.imshow(<span class="string">'Gray'</span>, gray)</span><br><span class="line">star = cv.xfeatures2d.StarDetector_create()</span><br><span class="line">keypoints = star.detect(gray)</span><br><span class="line">sift = cv.xfeatures2d.SIFT_create()</span><br><span class="line">_, desc = sift.compute(gray, keypoints)</span><br><span class="line">print(desc.shape)</span><br><span class="line">mp.matshow(desc, cmap=<span class="string">'gist_rainbow'</span>,</span><br><span class="line">	fignum=<span class="string">'DESC'</span>)</span><br><span class="line">mp.title(<span class="string">'DESC'</span>, fontsize=<span class="number">20</span>)</span><br><span class="line">mp.xlabel(<span class="string">'Feature'</span>, fontsize=<span class="number">14</span>)</span><br><span class="line">mp.ylabel(<span class="string">'Sample'</span>, fontsize=<span class="number">14</span>)</span><br><span class="line">mp.tick_params(which=<span class="string">'both'</span>, top=<span class="literal">False</span>,</span><br><span class="line">	labeltop=<span class="literal">False</span>, labelbottom=<span class="literal">True</span>,</span><br><span class="line">	labelsize=<span class="number">10</span>)</span><br><span class="line">mp.show()</span><br></pre></td></tr></table></figure></p>
<h2 id="图像识别-1"><a href="#图像识别-1" class="headerlink" title="图像识别"></a>图像识别</h2><p>类似的特征描述矩阵必然源自类似的图像<br><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">import</span> warnings</span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> cv2 <span class="keyword">as</span> cv</span><br><span class="line"><span class="keyword">import</span> hmmlearn.hmm <span class="keyword">as</span> hl</span><br><span class="line">warnings.filterwarnings(<span class="string">'ignore'</span>,</span><br><span class="line">	category=DeprecationWarning)</span><br><span class="line">np.seterr(all=<span class="string">'ignore'</span>)</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">search_objects</span><span class="params">(directory)</span>:</span></span><br><span class="line">	directory = os.path.normpath(directory)</span><br><span class="line">	<span class="keyword">if</span> <span class="keyword">not</span> os.path.isdir(directory):</span><br><span class="line">		<span class="keyword">raise</span> IOError(<span class="string">"The directory '"</span> +</span><br><span class="line">			directory + <span class="string">"' doesn't exist!"</span>)</span><br><span class="line">	objects = &#123;&#125;</span><br><span class="line">	<span class="keyword">for</span> curdir, subdirs, files <span class="keyword">in</span> os.walk(</span><br><span class="line">		directory):</span><br><span class="line">		<span class="keyword">for</span> jpeg <span class="keyword">in</span> (file <span class="keyword">for</span> file <span class="keyword">in</span> files</span><br><span class="line">			<span class="keyword">if</span> file.endswith(<span class="string">'.jpg'</span>)):</span><br><span class="line">			path = os.path.join(curdir, jpeg)</span><br><span class="line">			label = path.split(os.path.sep)[<span class="number">-2</span>]</span><br><span class="line">			<span class="keyword">if</span> label <span class="keyword">not</span> <span class="keyword">in</span> objects:</span><br><span class="line">				objects[label] = []</span><br><span class="line">			objects[label].append(path)</span><br><span class="line">	<span class="keyword">return</span> objects</span><br><span class="line">train_objects = search_objects(</span><br><span class="line">	<span class="string">'../data/objects/training'</span>)</span><br><span class="line">train_x, train_y = [], []</span><br><span class="line"><span class="keyword">for</span> label, filenames <span class="keyword">in</span> train_objects.items():</span><br><span class="line">	descs = np.array([])</span><br><span class="line">	<span class="keyword">for</span> filename <span class="keyword">in</span> filenames:</span><br><span class="line">		image = cv.imread(filename)</span><br><span class="line">		gray = cv.cvtColor(image,</span><br><span class="line">			cv.COLOR_BGR2GRAY)</span><br><span class="line">		h, w = gray.shape[:<span class="number">2</span>]</span><br><span class="line">		f = <span class="number">200</span> / min(h, w)</span><br><span class="line">		gray = cv.resize(gray, <span class="literal">None</span>,</span><br><span class="line">			fx=f, fy=f)</span><br><span class="line">		star = cv.xfeatures2d.StarDetector_create()</span><br><span class="line">		keypoints = star.detect(gray)</span><br><span class="line">		sift = cv.xfeatures2d.SIFT_create()</span><br><span class="line">		_, desc = sift.compute(gray, keypoints)</span><br><span class="line">		<span class="keyword">if</span> len(descs) == <span class="number">0</span>:</span><br><span class="line">			descs = desc</span><br><span class="line">		<span class="keyword">else</span>:</span><br><span class="line">			descs = np.append(descs, desc, axis=<span class="number">0</span>)</span><br><span class="line">	train_x.append(descs)</span><br><span class="line">	train_y.append(label)</span><br><span class="line">models = &#123;&#125;</span><br><span class="line"><span class="keyword">for</span> descs, label <span class="keyword">in</span> zip(train_x, train_y):</span><br><span class="line">	model = hl.GaussianHMM(</span><br><span class="line">		n_components=<span class="number">4</span>, covariance_type=<span class="string">'diag'</span>,</span><br><span class="line">		n_iter=<span class="number">1000</span>)</span><br><span class="line">	models[label] = model.fit(descs)</span><br><span class="line">test_objects = search_objects(</span><br><span class="line">	<span class="string">'../data/objects/testing'</span>)</span><br><span class="line">test_x, test_y, test_z = [], [], []</span><br><span class="line"><span class="keyword">for</span> label, filenames <span class="keyword">in</span> test_objects.items():</span><br><span class="line">	test_z.append([])</span><br><span class="line">	descs = np.array([])</span><br><span class="line">	<span class="keyword">for</span> filename <span class="keyword">in</span> filenames:</span><br><span class="line">		image = cv.imread(filename)</span><br><span class="line">		test_z[<span class="number">-1</span>].append(image)</span><br><span class="line">		gray = cv.cvtColor(image,</span><br><span class="line">			cv.COLOR_BGR2GRAY)</span><br><span class="line">		h, w = gray.shape[:<span class="number">2</span>]</span><br><span class="line">		f = <span class="number">200</span> / min(h, w)</span><br><span class="line">		gray = cv.resize(gray, <span class="literal">None</span>,</span><br><span class="line">			fx=f, fy=f)</span><br><span class="line">		star = cv.xfeatures2d.StarDetector_create()</span><br><span class="line">		keypoints = star.detect(gray)</span><br><span class="line">		sift = cv.xfeatures2d.SIFT_create()</span><br><span class="line">		_, desc = sift.compute(gray, keypoints)</span><br><span class="line">		<span class="keyword">if</span> len(descs) == <span class="number">0</span>:</span><br><span class="line">			descs = desc</span><br><span class="line">		<span class="keyword">else</span>:</span><br><span class="line">			descs = np.append(descs, desc, axis=<span class="number">0</span>)</span><br><span class="line">	test_x.append(descs)</span><br><span class="line">	test_y.append(label)</span><br><span class="line">pred_test_y = []</span><br><span class="line"><span class="keyword">for</span> descs <span class="keyword">in</span> test_x:</span><br><span class="line">	best_score, best_label = <span class="literal">None</span>, <span class="literal">None</span></span><br><span class="line">	<span class="keyword">for</span> label, model <span class="keyword">in</span> models.items():</span><br><span class="line">		score = model.score(descs)</span><br><span class="line">		<span class="keyword">if</span> (best_score <span class="keyword">is</span> <span class="literal">None</span>) <span class="keyword">or</span> \</span><br><span class="line">			(best_score &lt; score):</span><br><span class="line">			best_score, best_label = \</span><br><span class="line">				score, label</span><br><span class="line">	pred_test_y.append(best_label)</span><br><span class="line">i = <span class="number">0</span></span><br><span class="line"><span class="keyword">for</span> label, pred_label, images <span class="keyword">in</span> zip(</span><br><span class="line">	test_y, pred_test_y, test_z):</span><br><span class="line">	<span class="keyword">for</span> image <span class="keyword">in</span> images:</span><br><span class="line">		i += <span class="number">1</span></span><br><span class="line">		cv.imshow(<span class="string">'&#123;&#125; - &#123;&#125; &#123;&#125; &#123;&#125;'</span>.format(</span><br><span class="line">			i, label, <span class="string">'=='</span> <span class="keyword">if</span></span><br><span class="line">			label == pred_label <span class="keyword">else</span> <span class="string">'!='</span>,</span><br><span class="line">			pred_label), image)</span><br><span class="line">cv.waitKey()</span><br></pre></td></tr></table></figure></p>

      
    </div>

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/AI进阶/" rel="tag"># AI进阶</a>
          
            <a href="/tags/机器学习/" rel="tag"># 机器学习</a>
          
            <a href="/tags/图像识别/" rel="tag"># 图像识别</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/04/20/ml/语音识别/" rel="next" title="机器学习-语音识别">
                <i class="fa fa-chevron-left"></i> 机器学习-语音识别
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/05/17/ml/人脸识别/" rel="prev" title="机器学习-人脸识别">
                机器学习-人脸识别 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.JPG" alt="任成">
            
              <p class="site-author-name" itemprop="name">任成</p>
              <div class="site-description motion-element" itemprop="description"></div>
          </div>

          

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL0NvZGVyQ3VydmU=" title="GitHub &rarr; https://github.com/CoderCurve"><i class="fa fa-fw fa-github"></i>GitHub</span>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <span class="exturl" data-url="bWFpbHRvOnJlbmNoZW5nMTFAaWNsb3VkLmNvbQ==" title="E-Mail &rarr; mailto:rencheng11@icloud.com"><i class="fa fa-fw fa-envelope"></i>E-Mail</span>
                </span>
              
            </div>
          

          

          
          

          
            
          
          

        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#图像识别"><span class="nav-number">1.</span> <span class="nav-text">图像识别</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#OpenCV基础"><span class="nav-number">1.1.</span> <span class="nav-text">OpenCV基础</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#边缘检测"><span class="nav-number">1.2.</span> <span class="nav-text">边缘检测</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#亮度提升"><span class="nav-number">1.3.</span> <span class="nav-text">亮度提升</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#角点检测"><span class="nav-number">1.4.</span> <span class="nav-text">角点检测</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#STAR特征检测"><span class="nav-number">1.5.</span> <span class="nav-text">STAR特征检测</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#SIFT特征检测"><span class="nav-number">1.6.</span> <span class="nav-text">SIFT特征检测</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#STAR-SIFT特征描述矩阵"><span class="nav-number">1.7.</span> <span class="nav-text">STAR-SIFT特征描述矩阵</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#图像识别-1"><span class="nav-number">1.8.</span> <span class="nav-text">图像识别</span></a></li></ol></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>
  


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">  <span class="exturl" data-url="aHR0cDovL3d3dy5iZWlhbi5taWl0Lmdvdi5jbg==">京ICP备18001214号 </span>&copy; 2014 – <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">任成</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
    <span title="站点总字数">277k</span>
  

  
</div>









        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  <script src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>


  


  <script src="/js/utils.js?v=7.1.2"></script>

  <script src="/js/motion.js?v=7.1.2"></script>



  
  


  <script src="/js/affix.js?v=7.1.2"></script>

  <script src="/js/schemes/pisces.js?v=7.1.2"></script>



  
  <script src="/js/scrollspy.js?v=7.1.2"></script>
<script src="/js/post-details.js?v=7.1.2"></script>



  


  <script src="/js/next-boot.js?v=7.1.2"></script>


  

  
  <script src="/js/exturl.js?v=7.1.2"></script>


  

  


  


  
  <script>
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url).replace(/\/{2,}/g, '/');
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x"></i></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x"></i></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  
  

  
  

  


  

  
<script>
if ($('body').find('pre.mermaid').length) {
  $.ajax({
    type: 'GET',
    url: '//cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js',
    dataType: 'script',
    cache: true,
    success: function() {
      mermaid.initialize({
        theme: 'forest',
        logLevel: 3,
        flowchart: { curve: 'linear' },
        gantt: { axisFormat: '%m/%d/%Y' },
        sequence: { actorMargin: 50 }
      });
    }
  });
}
</script>


  

  

  

  

  

  

  

  

  

</body>
</html>
